﻿using System;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace VlcWebTvN8
{
    public class UdpStream:Stream
    {
        UdpClient _udpClient;
        
        public UdpStream(int port)
        {
            _udpClient = new UdpClient(port);
        }


        public override void Flush()
        {
            throw new NotSupportedException();
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotSupportedException();
        }

        public override void SetLength(long value)
        {
            throw new NotSupportedException();
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
            byte[] data = _udpClient.Receive(ref anyIP);

            Buffer.BlockCopy(data,0,buffer,offset,data.Length);
            return data.Length;
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            throw new NotSupportedException();
        }

        public override bool CanRead
        {
            get { return true; }
        }

        public override bool CanSeek
        {
            get { return false; }
        }

        public override bool CanWrite
        {
            get { return false; }
        }

        public override long Length
        {
            get { return _position; }
        }

        private long _position;
        public override long Position
        {
            get { return _position; }
            set { throw new NotSupportedException(); }
        }
    }
}